package com.example.demo.customer;

import com.example.demo.Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class CustomerService {

    private final CustomerRepo customerRepo;

    @Autowired

    public CustomerService(CustomerRepo customerRepo){
        this.customerRepo = customerRepo;
    }
    List<Customer> getCustomers(){
       return customerRepo.getCustomers();
    }

    Customer getCustomer(Long id){
        return getCustomers()
                .stream()
                .filter(customer -> Objects.equals(customer.getId(),  id))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("customer 无法找到"));

    }


}
